import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution914 {
    public boolean hasGroupsSizeX(int[] deck) {
        Map<Integer,Integer> map=new HashMap<>();
        for (int i : deck) {
            map.put(i,map.getOrDefault(i,0)+1);
        }
        List<Integer> list=new ArrayList<>(map.values());
        int gcd=list.get(0);
        for (int i=1;i<list.size();i++){
            gcd=gcd(gcd,list.get(i));
        }
        if (gcd==1){
            return false;
        }
        for (int i=0;i<list.size();i++){
            if (list.get(i)%gcd!=0){
                return false;
            }
        }
        return true;
    }

    private int gcd(int a, int b) {
        if (a<b){
            int t=a;
            a=b;
            b=t;
        }
        return a%b==0?b:gcd(b,a%b);
    }

    public static void main(String[] args) {
        System.out.println(new Solution914().hasGroupsSizeX(new int[]{1,1,1,2,2,2,3,3}));
    }
}
